app.controllers.ListController = new Ext.Controller({
	createNewList: function(options) {
		app.views.viewport.setActiveItem(
			app.views.NewListView, options.animation
		);
	},
	
	cancelCreate: function(options) {
		app.stores.checkLists.load();

		app.views.viewport.setActiveItem(
			app.views.ListView, options.animation
		);
	},
	
	createEmptyList: function(options) {
	
		app.stores.checkLists.load();
		
		app.views.viewport.setActiveItem(
			app.views.ListView, options.animation
		);
	},
	
	editList: function(options) {
		app.stores.checkLists.load();
		
		var liId = options.id;
		
		var theList = null;
		
		for (var index = 0; index < app.stores.checkLists.getCount(); index++) {
			
			var record = app.stores.checkLists.getAt(index);
			
			if ( record.get('id')== liId) {
				theList = record;
				break;
			}
		}

		
		if (theList) {
			app.views.ListManageView.updateWithRecord(theList);
			
			app.views.viewport.setActiveItem(
				app.views.ListManageView, options.animation
			);
		}
	},
	
	displayDetail: function(options) {
		
		app.stores.checkLists.sync();
		app.stores.checkLists.load();
		
		var liId = options.id;
		
		var theList = null;
		
		for (var index = 0; index < app.stores.checkLists.getCount(); index++) {
			
			var record = app.stores.checkLists.getAt(index);
			
			if ( record.get('id')== liId) {
				theList = record;
				break;
			}
		}
				
		// console.log('found list name ' + theList.get('listName'));
		
		if (theList) {
					
			app.views.ListDetailView.updateWithRecord(theList);
			
			app.views.viewport.setActiveItem(
				app.views.ListDetailView, options.animation
			);
		}
	},
	
	createNewItem: function(options) {
		var liId = options.id;
		
		app.views.NewItemView.prepCache(liId);
		app.views.viewport.setActiveItem(
			app.views.NewItemView, options.animation
		);
	},
	
	updateItem: function(options) {
	
		app.stores.checkLists.load();
		
		var liId = options.liId;
		
		var itemId = options.itemId;
		
		var theList = null;
		
		for (var index = 0; index < app.stores.checkLists.getCount(); index++) {
			
			var record = app.stores.checkLists.getAt(index);
			
			if ( record.get('id')== liId) {
				theList = record;
				break;
			}
		}

		
		if (theList) {
			app.views.ItemEditView.updateWithRecord(theList, itemId);
			
			app.views.viewport.setActiveItem(
				app.views.ItemEditView, options.animation
			);
		}
	}
	
	
});
